package mylab.starters.sms.config.tencent;

import lombok.RequiredArgsConstructor;
import mylab.starters.sms.config.SmsAutoConfiguration;
import mylab.starters.sms.config.SmsProperties;
import mylab.starters.sms.support.tencent.TencentSmsTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AutoConfigureAfter(SmsAutoConfiguration.class)
@ConditionalOnProperty(value = TencentAutoConfiguration.PREFIX, havingValue = "true")
public class TencentAutoConfiguration {

    static final public String PREFIX = SmsProperties.PREFIX + ".tencent.enabled";

    final private SmsProperties smsProperties;

    @Bean
    @ConditionalOnMissingBean
    public TencentSmsTemplate tencentSmsTemplate() {
        return new TencentSmsTemplate(smsProperties.getTencent());
    }
}
